using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using System.Drawing;

namespace SBPweb.Themes.Windows.Skins
{
	/// <summary>
	/// Class of Border
	/// </summary>
	public class Border
	{
		private Color mLeftColor = new Color();
		private Color mRightColor = new Color();
		private Color mTopColor = new Color();
		private Color mBottomColor = new Color();
		private Color mAllColor = new Color();

		/// <summary>
		/// Constructor of Border
		/// </summary>
		public Border()
		{
			mLeftColor = System.Drawing.Color.FromArgb(136, 176, 228);
			mRightColor = System.Drawing.Color.FromArgb(136, 176, 228);
			mTopColor = System.Drawing.Color.FromArgb(136, 176, 228);
			mBottomColor = System.Drawing.Color.FromArgb(136, 176, 228);
		}

		/// <summary>
		/// Constructor of Border
		/// </summary>
		/// <param name="left">left color</param>
		/// <param name="right">right color</param>
		/// <param name="top">top color</param>
		/// <param name="bottom">bottom color</param>
		public Border(Color left, Color right, Color top, Color bottom)
		{
			mLeftColor = left;
			mRightColor = right;
			mTopColor = top;
			mBottomColor = bottom;
		}

		/// <summary>
		/// Constructor of Border
		/// </summary>
		/// <param name="node">xml node</param>
		public Border(XmlNode node)
		{
			XmlAttribute leftAtt = node.Attributes["Left"];
			XmlAttribute rightAtt = node.Attributes["Right"];
			XmlAttribute topAtt = node.Attributes["Top"];
			XmlAttribute bottomAtt = node.Attributes["Bottom"];

			if (node != null && leftAtt != null && topAtt != null
				&& rightAtt != null && bottomAtt != null)
			{
				string left = leftAtt.Value;
				string right = rightAtt.Value;
				string top = topAtt.Value;
				string bottom = bottomAtt.Value;

				string[] leftBorderColor = left.Split(',');
				string[] rightBorderColor = right.Split(',');
				string[] topBorderColor = top.Split(',');
				string[] bottomBorderColor = bottom.Split(',');

				if (leftBorderColor.Length < 3)
				{
					if (!left.StartsWith("$"))
					{
						mLeftColor = Color.FromName(left);
					}
				}
				else
				{
					mLeftColor = Color.FromArgb(int.Parse(leftBorderColor[0]), int.Parse(leftBorderColor[1]), int.Parse(leftBorderColor[2]));
				}

				if (rightBorderColor.Length < 3)
				{
					if (!right.StartsWith("$"))
					{
						mRightColor = Color.FromName(right);
					}
				}
				else
				{
					mRightColor = Color.FromArgb(int.Parse(rightBorderColor[0]), int.Parse(rightBorderColor[1]), int.Parse(rightBorderColor[2]));
				}

				if (topBorderColor.Length < 3)
				{
					if (!top.StartsWith("$"))
					{
						mTopColor = Color.FromName(top);
					}
				}
				else
				{
					mTopColor = Color.FromArgb(int.Parse(topBorderColor[0]), int.Parse(topBorderColor[1]), int.Parse(topBorderColor[2]));
				}

				if (bottomBorderColor.Length < 3)
				{
					if (!bottom.StartsWith("$"))
					{
						mBottomColor = Color.FromName(bottom);
					}
				}
				else
				{
					mBottomColor = Color.FromArgb(int.Parse(bottomBorderColor[0]), int.Parse(bottomBorderColor[1]), int.Parse(bottomBorderColor[2]));
				}
				
			}

		}

		/// <summary>
		/// Left color
		/// </summary>
		public Color LeftColor
		{
			get
			{
				return mLeftColor;
			}
		}

		/// <summary>
		/// Right color
		/// </summary>
		public Color RightColor
		{
			get
			{
				return mRightColor;
			}
		}

		/// <summary>
		/// Top color
		/// </summary>
		public Color TopColor
		{
			get
			{
				return mTopColor;
			}
		}

		/// <summary>
		/// Bottom color
		/// </summary>
		public Color BottomColor
		{
			get
			{
				return mBottomColor;
			}
		}

		/// <summary>
		/// All color (if not equals, returns the left)
		/// </summary>
		public Color AllColor
		{
			get
			{

				if (mLeftColor.ToString() == mRightColor.ToString() & 
					mLeftColor.ToString() == mTopColor.ToString() & 
					mLeftColor.ToString() == mBottomColor.ToString())
				{
					return mLeftColor;
				}
				return mAllColor;
			}
		}
	}
}
